package admin.service.impl;

import admin.entity.Admin;
import admin.service.aa.AdminService;
import menu.service.Impl.MenuServiceImpl;

import java.util.Scanner;

public class AdminServiceImpl implements AdminService {
    public static Admin admin;
    static int loginError;

    @Override
    public void initializeAdmin() {
        admin = new Admin();
        admin.setLoginName("admin");
        admin.setLoginPassword("123456");
        admin.setAdminName("管理员");
        loginError = 5;
    }

    @Override
    public void adminLogin() {
        for (int error = 1; error <= loginError; error++) {
            System.out.println("----------管理员登录----------");
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入管理员账号：");
            String loginName = scanner.next();
            System.out.println("请输入管理员密码：");
            String loginPassword = scanner.next();
            if (admin.getLoginName().equals(loginName) && admin.getLoginPassword().equals(loginPassword)) {
                System.out.println("欢迎" + admin.getAdminName() + "登录");
                return;
            } else {
                System.out.println("账号或密码错误请重新输入，已错误" + error + "次，超过" + loginError + "自动退出到登录页面");
                if (error == loginError) {
                    System.out.println("尝试次数过多，自动退出中");
                    return;
                }
            }
        }
    }

    @Override
    public void adminRevisePassword() {
        System.out.println("----管理员登录------");
        //1.监听输入
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入管理员密码：");
        String loginPassword = scanner.next();
        //1.当前密码不能与原密码重复
        if (!admin.getLoginPassword().equals(loginPassword)) {
            admin.setLoginPassword(loginPassword);
            System.out.println("修改密码成功");
            new MenuServiceImpl().loginMenu();
        } else {
            System.out.println("新密码不能与原密码一样");
        }
        //2.当前密码不能包含原密码
    }
}



